package logic

import (
	"context"
	"gozerogateway/rpc/common/lib"

	"gozerogateway/common/errorx"
	"time"

	"gozerogateway/rpc/tenant/internal/svc"
	"gozerogateway/rpc/tenant/tenantclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type AppStatLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAppStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppStatLogic {
	return &AppStatLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AppStatLogic) AppStat(in *tenantclient.StatisticReq) (*tenantclient.StatisticsResp, error) {
	// todo: add your logic here and delete this line

	if _, err := l.svcCtx.AppModel.FindOne(l.ctx, in.Id); err != nil {
		return nil, errorx.NewDefaultError("app is not exist")
	}

	todayList := []int64{}
	for i := 0; i <= time.Now().In(lib.TimeLocation).Hour(); i++ {
		todayList = append(todayList, 0)
	}
	yesterdayList := []int64{}
	for i := 0; i <= 23; i++ {
		yesterdayList = append(yesterdayList, 0)
	}
	return &tenantclient.StatisticsResp{
		Today:     todayList,
		Yesterday: yesterdayList,
	}, nil
}
